<!DOCTYPE html>
<html>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
	    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	    <title>Hello APP</title>
	    <link rel="stylesheet" type="text/css" href="../../css/index.css" />
	</head>
	<style type="text/css">
		.warp{width: 100%;}

		.info-box{width: 100%;}
		.info-box .info-one{align-items: center;height: 50px;padding: 0 15px;background: #FFFFFF;box-sizing: border-box;font-size: 14px;color: #4D4F50;}
		.info-box .info-one .r{text-align: right;padding: 10px 0;line-height: 30px;box-sizing: border-box;text-align: right;color: #999999;}
		.info-box .info-one.goto{background: url(../../image/main3/main3_goto.png) no-repeat right 10px center #FFFFFF;background-size:14px;padding-right: 30px;}
		.info-box .info-one .head{width: 40px;height: 40px;border-radius:50%;}
		.info-box .info-one.h{height: 60px;}

	</style>
	<body>
		<div id="vue" class="warp">
			<div class="info-box">
	        	<div class="info-one flex goto h" tapmode onclick="fnChangeUlogo()">
	        		<div class="text flex1">头像</div>
	        		<div class="head bgpic" :style="{backgroundImage:'url('+udata.avatar+')'}"></div>
	        	</div>
	        	<div class="info-one flex goto border-top" tapmode onclick="xiuName()">
	        		<div class="text">用户昵称</div>
	        		<div class="r flex1" v-text="udata.nickname"></div>
	        	</div>
	        	<div class="info-one flex goto border-top" tapmode onclick="sel_sex()">
	        		<div class="text">性别</div>
					<div class="r flex1" v-text="udata.sex"></div>
	        	</div>
	        	<div class="info-one flex goto border-top" tapmode onclick="sel_birthday()">
	        		<div class="text">生日</div>
	        		<div class="r flex1" v-text="udata.srdate"></div>
	        	</div>
			</div>
		</div>
	</body>
</html>
<script type="text/javascript" src="../../script/base.min.js" id="loadjs" data-js="L/swiper.min,L/lazyload,L/h-tool"></script>
<script type="text/javascript">
	define(function (require, exports, module) {
		var oosinfo = lanYun.getStorage('imageData') || null;
		if(!localStorage.birthdays){
			lanYun.bithdays();
		}
		setData = function () {
			var udata = lanYun.getUdata();
			//console.log(JSON.stringify(udata));
			lanYun.vue.udata = udata;
		};
		lanYun.newVue('#vue',{
			udata:{}
		},function() {

		});
		setData();

		onShow = function () {
			var reshpage = lanYun.getStorage('reshpage');
			if(reshpage){
				lanYun.rmStorage('reshpage');
				setData();
			}
		}

		//绑定身份证号
		bandSfz = function (tis){
			var dst = tis.dataset;
			//console.log(dst.type);
			if(dst.type == 1){
				return;
			}
			lanYun.openWin('main3/band_sfz.html', {
				win:'win',
				title:"绑定身份证号"
		   });
		}
		//修改用户昵称
		xiuName = function (tis){
			lanYun.dialog.input({fname:'diaLogBox1',title:'输入昵称', button:['取消','确定'],value:""},function(ret){
	            if (ret.index == 0) return;
				setinfo("nickname",ret.value);
	        });
		}
		//筛选性别
		sel_sex = function(){
			lanYun.actionSelect({
				col:1,
				data:[{type:1,name:'男'},{type:2,name:'女'}],
				title:'性别',
				successCall:function(result){
					if(result && result.eventType == 'ok' && result.selectedInfo){
						var result_data = result.selectedInfo[0];
						setinfo('sex',result_data.name);
					}
				}
			});
		};
		//弹出出生日期选择窗口
		sel_birthday = function (){
			lanYun.actionSelect({
				col:3,
				cachekey:'birthdays',
				title:'出生日期',
				successCall:function(result){
					if(result && result.eventType == 'ok' && result.selectedInfo){
						var month = result.level2 < 10 ? '0'+result.level2 : result.level2;
						var date = result.level3 < 10 ? '0'+result.level3 : result.level3;
						//console.log(result.level1+'-'+month+'-'+date);
						setinfo('srdate',result.level1+'-'+month+'-'+date);
					}
				}
			});
		};
		// 更换头像
		fnChangeUlogo = function() {
			lanYun.getPermission(['camera','photos']);
			api.actionSheet({buttons: ['拍照', '相册选取'],style: {fontNormalColor: '#333',fontPressColor: '#333'}}, function(ret, err) {
				if (ret.buttonIndex == 3)return '';
				var souType = 'album'; //相机
				if (ret.buttonIndex == 1)souType = 'camera';
				api.getPicture({sourceType: souType,mediaValue: 'pic',destinationType: 'url',quality: 80}, function(ret, err) {
					if (ret && ret.data) {
						lanYun.openCaiQie(ret.data);
					}
				});
			});
		};
		//裁切后上传
		caiqieCallBack = function(path){
			if(!path){
				lanYun.toast('请选择上传文件');
				return;
			}
			if(!oosinfo){
				lanYun.toast('网路访问超时,请重试');
				return;
			}
			upfile(path);
		};
		// 更新头像
		upfile = function(path){
			var ext = lanYun.getFileExt(path);
			var file = oosinfo.key+lanYun.randStr(10)+ext;
			var urlFile = oosinfo.url+'/'+file;
			lanYun.showProgress({type:2});
			api.ajax({url: oosinfo.url,method: 'post',data: {values:{key: file,OSSAccessKeyId: oosinfo.OSSAccessKeyId,success_action_status: oosinfo.success_action_status,policy:oosinfo.policy,signature: oosinfo.signature},files: {file:path}}}, function(res, err) {
				lanYun.hideProgress();
				if(err && err.statusCode == 200){
					setinfo("avatar",urlFile);
				}else{
					lanYun.toast('头像上传失败');
				}
			});
		};
		//修改信息
		setinfo = function (type,val){
			lanYun.post('user/editInfo',{field:type,value:val},function(ret){
				//console.log(JSON.stringify(ret));
				if(ret.errcode==0){
					lanYun.vue.udata = ret.data;
					lanYun.updateUdata(ret.data, 1);
					lanYun.toast('修改成功');
				}else {
					lanYun.toast('修改失败');
				}
			},2)
		}
		//打开页面
		open_page = function (tis) {
			var dst = tis.dataset;
			//console.log(JSON.stringify(tis));
			lanYun.openWin(dst.url, {
				win:'win',
				title:dst.title,
				frameParam : dst
		   });
		}
	});
</script>
